<template>
  <el-card>
    <div class="top">
      <el-breadcrumb separator=">">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>申请信息</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-table
      max-height="500"
      :data="tableData"
      style="width: 100%">
      <el-table-column
        label="姓名"
        width="180">
        <template slot-scope="scope">
          <!-- <i class="el-icon-time"></i> -->
          <span style="margin-left: 10px">{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="电话"
        width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.phone }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="电话"
        width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.mailbox }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="电话"
        width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.message }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button> -->
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- <el-pagination
    layout="prev, pager, next"
    :total="totalPage">
  </el-pagination> -->
  </el-card>
</template>

<script>
import { contactInfoShow, deleteData } from "../../utils/api";
export default {
  data() {
    return {
      tableData: [],
      totalPage: "",
      deleteParams: {
        type: "point",
        id: ""
      }
    };
  },
  created() {
    this.getContectInfo();
  },
  methods: {
    // 删除指定ID数据
    handleDelete(index, row) {
      this.deleteParams.id = row.point_id;
      this.$confirm("确认删除？").then(() => {
        deleteData(this.deleteParams).then(
          this.$message("删除成功"),
          this.getContectInfo()
        );
      });
    },
    // 预处理返回的申请信息 将页数提取出来
    dealContectInfo() {
      this.totalPage = this.tableData.pop();
      this.totalPage = Number(this.totalPage.totalPageNum);
    },
    // 获取申请数据
    getContectInfo() {
      contactInfoShow().then(res => {
        this.tableData = res.data.results;
        this.dealContectInfo();
      });
    },
    handleEdit(index, row) {
      console.log(index, row);
    }
    // handleDelete(index, row) {
    //   console.log(index, row);
    // }
  }
};
</script>

<style lang="less" scoped>
  .top {
    box-sizing: border-box;
    width: 100%;
    padding: 20px 0px 20px 20px;
    background: #fff;
    border-bottom: 1px solid #eee;
  }
</style>
